﻿Public Class ConfigPackage
    Inherits System.Web.UI.Page

    Private dt As DataTable
    Private Property DataSource As Data.DataTable
        Get
            Return dt
        End Get
        Set(ByVal value As Data.DataTable)
            dt = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
        Dim info As Entity.PackageItem = New Entity.PackageItem
        info.package_id = txtPackageCode.Text.Trim

        If Not String.IsNullOrEmpty(txtPackageRVValue.Text.Trim) Then
            info.package_rv = Convert.ToDecimal(txtPackageRVValue.Text.Trim)
        End If

        If Not String.IsNullOrEmpty(txtPackageAmount.Text.Trim) Then
            info.package_amount = Convert.ToDecimal(txtPackageAmount.Text.Trim)
        End If

        If Not String.IsNullOrEmpty(txtPackageDesc.Text.Trim) Then
            info.package_desc = txtPackageDesc.Text.Trim
        End If

        If ddlPackageStatus.SelectedValue <> "-" Then
            info.record_status = ddlPackageStatus.SelectedValue
        End If

        DataSource = BL.Configuration.GetPackage(info)

        Bind(0)
    End Sub

    Private Sub Bind(ByVal pageIndex As Integer)
        Me.gvList.DataSource = DataSource
        Me.gvList.PageIndex = pageIndex
        Me.gvList.DataBind()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
        Response.Redirect("ConfigPackage.aspx", False)
    End Sub

    Private Sub gvList_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvList.PageIndexChanging
        Bind(e.NewPageIndex)
    End Sub

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
        Me.Response.Redirect("~/ConfigPackageDetail.aspx?action=ADD", False)
    End Sub

    Protected Sub gvList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gvList.SelectedIndexChanged
        Try
            'GlobalApp.DataSourceEditOfficer = BL.Officer.LoadProfile(Me.gvList.SelectedValue)
            Response.Redirect("~/ConfigPackageDetail.aspx?action=EDIT&packageid=" & Me.gvList.SelectedValue, False)
        Catch ex As Exception
            Me.Master.Alert("ไม่สามารถดึงข้อมูลที่ท่านต้องการได้")
            Common.LogError.AddLogException(ex)
        End Try
    End Sub
End Class